<?php

    /**
     *      [Discuz!] (C)2001-2099 Comsenz Inc.
     *      This is NOT a freeware, use is subject to license terms
     *      $Id: table_mobile_setting.php 31281 2012-08-03 02:29:27Z zhangjie $
     */

    if (!defined('IN_DISCUZ')) {
        exit('Access Denied');
    }

    class table_cloud_app_manage extends discuz_table {

        public function __construct() {
            $this->_table = 'cloud_app_manage';
            $this->_pk = 'camid';

            parent::__construct();
        }

        //插入数据库
        public function insert($arr) {
            return DB::insert($this->_table, $arr, true);
        }

        //更新数据库
        public function update($camid, $data) {
            $camid = intval($camid);
            if (!$data) {
                return;
            }
            return DB::update($this->_table, $data, DB::field($this->_pk, $camid));
        }

        //查找某条记录
        public function fetch_info($id) {
            $id = intval($id);
            return DB::fetch_first("SELECT * FROM %t WHERE camid=%d", array($this->_table, $id));
        }

        //查找某条记录
        public function fetch_app_info($id,$caid) {
            $id = intval($id);
            return DB::fetch_first("select * from ". DB::table($this->_table).' as am inner join '. DB::table('cloud_app_role').' as ar on am.carid = ar.id WHERE camid='.$id.' and am.caid='.$caid);
        }

        //查询所有limt数据
        public function fetch_all_limit($start = 0, $limit = 0) {
            return DB::fetch_all('SELECT * FROM ' . DB::table($this->_table) .' order by '.DB::order('lasttime','desc'). DB::limit($start, $limit));
        }

        //根据应用名称查询
        public function fetch_first_by_name($name, $caid) {
            return DB::fetch_first("SELECT * FROM " . DB::table($this->_table) . " where name='" . $name . "' and caid=" . $caid);
        }

        //查询所有limt数据
        public function fetch_app_limit($caid,$start = 0, $limit = 0) {
            return DB::fetch_all('SELECT * FROM ' . DB::table($this->_table) .' where caid = '.$caid.' order by '.DB::order('lasttime','desc'). DB::limit($start, $limit));
        }

        //查询所有limt数据
        public function fetch_app_count($caid) {
            return DB::fetch_first('SELECT count(camid) as count  FROM ' . DB::table($this->_table) .' where caid = '.$caid);
        }

        //查询所有limt数据
        public function fetch_app_by_carid($carid) {
            return DB::fetch_all('SELECT * FROM ' . DB::table($this->_table) .' where carid = '.$carid.' order by '.DB::order('lasttime','desc'));
        }


        //查询count
        public function fetch_all_count() {
            return DB::fetch_first('SELECT count(camid) as count FROM ' . DB::table($this->_table));
        }

    }